<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Cache;
use app\index\model\Weixin;
define("TOKEN", "weixin");
class Index extends Controller
{

    public function index(){
        try{
            $weixin =new Weixin();
            if (!isset($_GET['echostr'])) {
                $is_access_token =  Cache::get('access_token');
                if(!empty($is_access_token)){
                    $weixin->responseMsg();//回复消息方法
                }else{
                    $weixin->getAccessToken();
                    $weixin->responseMsg();//回复消息方法
                }
            }else{
                ob_clean();
                $weixin->valid();
            }
        }catch (\Exception $e){
            $weixin->write_log($e->getMessage(),1);
        }
    }

}
